/********************************************************************************
 * Project Name		[JavaEE_JDBC]
 * File Name     	[UserDaoFactory.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package dao;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * 使用单例和工厂模式构建UserDaoFactory
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class UserDaoFactory {

	private UserDao userDao = null;

	private static UserDaoFactory factory = new UserDaoFactory();

	private UserDaoFactory() {
		Properties prop = new Properties();
		try {
			InputStream in = null;
			in = new FileInputStream("src/dao/daoconfig.properties");
			prop.load(in);

			String className = prop.getProperty("userdao");
			userDao = (UserDao) Class.forName(className).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static UserDaoFactory getUserDaoFactoryInstance() {
		return factory;
	}

	public UserDao getUserDaoInstance() {
		return userDao;
	}
}
